﻿using System.ComponentModel.DataAnnotations;
using System.Runtime.InteropServices;
using System.Text;

namespace Homework17
{
    enum Gender
    {
        Male,
        Female
    }

    internal class Program
    {
        const int COUNT = 10000;
        const string FILENAME = "D:\\data.txt";

        /// <summary>
        /// 创建数据集
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //创建随机数，年龄
            Random random = new Random();
            double mean = 45.0; // 正态分布的均值  
            double stdDev = 5.0; // 正态分布的标准差  
            List<double> Age = new List<double>();
            //循环,输出正态分布的随机数
            for (int i = 0; i < COUNT ; i++)
            {
                double u1 = random.NextDouble(); // [0,1) 范围内的均匀分布随机数  
                double u2 = random.NextDouble(); // [0,1) 范围内的均匀分布随机数  

                // Box-Muller变换  
                double z0 = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Cos(2.0 * Math.PI * u2);
                // 由于我们只需要一个正态分布的样本集合，这里只取z0，z1可以被忽略或用于生成另一个独立的样本集合  

                // 调整均值和标准差  
                double normalSample = mean + z0 * stdDev;

                Age.Add(normalSample);
            }
            //如果Age<0则让它等于0,>100让它等于100
            for (int i = 0; i < Age.Count; i++)
            {
                if (Age[i] < 0)
                    Age[i] = 0;
            }
            for (int j = 0; j < Age.Count; j++)
            {
                if (Age[j] > 100)
                    Age[j] = 100;
            }
            //名字
            const int MINLENGTH = 3;//最少字符数
            const int MAXLENGTH = 5;//最多字符数
            const string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            List<string> Name = new List<string>();

            for (int i = 0; i < COUNT; i++)
            {
                int length = random.Next(MINLENGTH, MAXLENGTH + 1);
                StringBuilder word = new StringBuilder(length);

                // First letter is always uppercase  
                word.Append(letters[random.Next(letters.Length)]);

                // Subsequent letters are lowercase  
                const string lowerLetters = "abcdefghijklmnopqrstuvwxyz";
                for (int j = 1; j < length; j++)
                {
                    word.Append(lowerLetters[random.Next(lowerLetters.Length)]);
                }

                Name.Add(word.ToString());
            }
            //生日
            List<string> birthYear = new List<string>();
            for (int i = 0; i < COUNT; i++)
            {
                double Year = (double)DateTime.Today.Year - Age[i];
                birthYear.Add(Year.ToString("yyyy"));
            }


            List<string> dates = new List<string>();

            for (int i = 0; i < COUNT; i++)
            {
                string date = GenerateRandomMonthDay(random);
                dates.Add(date);
            }
            static string GenerateRandomMonthDay(Random random)
            {
                int month = random.Next(1, 13); // 生成1到12的随机月份  
                int day;

                // 根据月份生成对应的天数范围  
                switch (month)
                {
                    case 1:
                    case 3:
                    case 5:
                    case 7:
                    case 8:
                    case 10:
                    case 12:
                        day = random.Next(1, 32); // 31天  
                        break;
                    case 4:
                    case 6:
                    case 9:
                    case 11:
                        day = random.Next(1, 31); // 30天  
                        break;
                    case 2:
                        // 2月有28或29天（这里不考虑闰年，所以固定28天）  
                        day = random.Next(1, 29);
                        break;
                    default:
                        throw new InvalidOperationException("Invalid month generated.");
                }

                // 格式化为MM-DD字符串  
                return month.ToString("D2") + "-" + day.ToString("D2");
            }
            List<string> fullDates = new List<string>();
            for (int i = 0; i < COUNT; i++)
            {
                string left = birthYear[i];
                string right = dates[i];

                // 左右合并字符串  
                string merged = left + "-" + right;
                fullDates.Add(merged);
            }
            //身高
            List<double> heights = new List<double>();
            for (int i = 0; i < COUNT; i++)
            {
                // 生成0.0到1.0之间的随机数  
                double scaledRandom = random.NextDouble();

                // 缩放到1.6到2.0的范围  
                double result = scaledRandom * (2.0 - 1.6) + 1.6;

                // 添加到列表中  
                heights.Add(result);
            }
            //性别
            List<Gender> genders = new List<Gender>();

            for (int i = 0; i < COUNT; i++)
            {
                // 随机生成0或1，然后转换为Gender枚举  
                Gender gender = random.Next(0, 2) == 0 ? Gender.Male : Gender.Female;

                // 添加到列表中  
                genders.Add(gender);
            }
            // 合并列表  
            List<string> mergedList = new List<string>();
            for (int i = 0; i < COUNT; i++)
            {
                mergedList.Add($"{fullDates[i]},{heights[i]},{genders[i]}");
            }
            //using (StreamWriter writer = new StreamWriter(FILENAME))
            //{
            //    writer.WriteLine(mergedList);
            //}
            Console.WriteLine(mergedList);


        }
    }
}





